import numpy as np
import torch
import pickle
import os
import re
from tqdm import tqdm
from datetime import datetime

videodt_format = "%Y%m%d%H%M"
radardt_format = "%Y%m%d%H%M%S"

allvideofolder='./VIDEO/'
allvideofolder_list=os.listdir(allvideofolder)
allvideofolder_list = sorted(allvideofolder_list, key=lambda x: int(re.findall('\d+', x)[0]))

allradardatafolder='./RADAR/'
allradardatafolder_list=os.listdir(allradardatafolder)
allradardatafolder_list = sorted(allradardatafolder_list, key=lambda x: int(re.findall('\d+', x)[0]))

same_folder=[]
for i in range(len(allvideofolder_list)):
    # video_strat_time=str(float(allvideofolder_list[i]))
    video_strat_timedt = datetime.strptime(str(allvideofolder_list[i]), videodt_format)
    video_strat_timestamp = video_strat_timedt.timestamp()
    for j in range(len(allradardatafolder_list)):
        radar_strat_timedt = datetime.strptime(str(allradardatafolder_list[j]), radardt_format)
        radar_strat_timestamp = radar_strat_timedt.timestamp()

        if abs(video_strat_timestamp-radar_strat_timestamp)<=100:
            # print(video_strat_timedt)
            # print(radar_strat_timedt)
            
            # print(abs(video_strat_timestamp-radar_strat_timestamp))
            same_folder.append([allvideofolder_list[i],allradardatafolder_list[j]])
